/* SPDX-License-Identifier: GPL-2.0 */
#include <common.h>
#include <asm/arch-apsilicon/boot_param.h>


union boot_params boot_params_stash __section(".data");
unsigned long sp_reg __section(".data");


static const char *const boot_device_name[] = {
	"BD_NONE",
	"BD_PFLASH",
	"BD_SDMC0",
	"BD_SDMC1",
	"BD_SPINOR",
	"BD_UART",
	"BD_BOOTROM"
};



#ifdef CONFIG_SPL_BUILD
#ifdef CONFIG_TPL_BUILD
static char *boot_stage = "[TPL]";
#else
static char *boot_stage = "[SPL]";
#endif
#else
static char *boot_stage = "[U-Boot]";
#endif



enum boot_device ap_get_boot_device(void)
{
	enum boot_device dev;
	static uint8_t silence = 0;

#ifdef CONFIG_SPL_BUILD
	/* SPL use a0 */
	dev = get_boot_device(boot_params_stash.r.a[0]);
#else
	/* U-Boot use a3 */
	dev = get_boot_device(boot_params_stash.r.a[3]);
#endif
	if(!silence) {
		silence = 1;
		printf("%s: Boot device = %d(%s)\n", boot_stage, dev, boot_device_name[dev]);
	}
	return dev;
}
